# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('pth' 'pth-devel')
pkgver=2.0.7
pkgrel=1
pkgdesc="The GNU Portable Threads"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/pth/"
groups=('base' 'base-devel')
license=('LGPL')
depends=('msys2-runtime')
source=(ftp://ftp.gnu.org/gnu/pth/$pkgname-$pkgver.tar.gz{,.sig}
        pth-2.0.7-2.src.patch
        msysize.patch)
md5sums=('9cb4a25331a4c4db866a31cbe507c793'
         'SKIP'
         '7b7c5f7d30b5f5365a230c89b222351b'
         'a884527bc128639bf6fd9d6ccf8121db')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"
  patch -p2 -i ${srcdir}/pth-2.0.7-2.src.patch
  patch -p1 -i ${srcdir}/msysize.patch

  libtoolize -cifv
  autoreconf -fvi
}

build() {
  cd "$pkgname-$pkgver"

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --mandir=/usr/share/man \
    --enable-shared \
    --disable-static \
    --enable-syscall-soft

  sed -i "s|awk=''|awk=/usr/bin/awk|g" shtool # "Cannot find a reasonable Awk"
  make -j1
  make -j1 DESTDIR="${srcdir}/dest" install
}

package_pth() {
  groups=('libraries')

  mkdir -p $pkgdir/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll $pkgdir/usr/bin/
  cp -rf ${srcdir}/dest/usr/share $pkgdir/usr/
}

package_pth-devel() {
  pkgdesc="Pth headers and libraries"
  groups=('development')
  options=('!staticlibs')
  depends=("pth=${pkgver}")

  mkdir -p $pkgdir/usr/bin
  cp -f ${srcdir}/dest/usr/bin/pth-config $pkgdir/usr/bin/
  cp -rf ${srcdir}/dest/usr/include $pkgdir/usr/
  cp -rf ${srcdir}/dest/usr/lib $pkgdir/usr/
}
